
package com.joysuch.wwyt.util;

import java.util.Arrays;
import java.util.List;

import cn.zlg.common.util.MimeUtils;

public class DocTypeUtils {

    static List<String> docSuffix = Arrays.asList("doc", "docx", "ppt", "pptx", "xls", "xlsx", "pdf", "txt", "rtf");

    /**
     * 根据后缀判断文件类型是文档、视频、音频、图片等
     * 
     * @param suffix
     *            后缀
     * @param defaultType
     *            默认值.找不到对应的格式时，返回此值
     * @return
     */
    public static String getDocType(String suffix, String defaultType) {
        if (suffix == null) {
            return defaultType;
        }
        suffix = suffix.toLowerCase();
        String format = MimeUtils.getMimeType(suffix);
        if (format == null) {
            return defaultType;
        }
        if (format.startsWith("video")) {
            return "video";
        } else if (format.startsWith("image")) {
            return "image";
        } else if (format.startsWith("audio")) {
            return "audio";
        } else if (docSuffix.contains(suffix)) {
            return "doc";
        }
        return defaultType;
    }

}
